#project info
TARGET		:= md
SOURCES		:= $(wildcard *.cpp)
OBJECTS		:= $(SOURCES:%.cpp=%.o)
BUILDDIR	:= build
CLFILE		:=1.cl

#required libs
#LD - dynamic, S - static
#OpenCL 
INCLUDEDIRS	:= $(AMDAPPSDKROOT)/include  $(AMDAPPSDKROOT)/samples/opencl/SDKUtil/include 
LIBDIRS 	:= $(AMDAPPSDKROOT)/lib/x86_64 

LLIBS 		:= 
SLIBS		:= OpenCL


LD_LIBLINK_PREFIX 	:= lib
LD_LIBLINK_SUFFIX 	:= .so
S_LIBLINK_PREFIX	:= -l
LD_LIBDIR_FLAG 		:= -L
C_INCLUDE_FLAG 		:= -I

ADDLLIBS 	:= $(foreach f, $(LLIBS), $(LD_LIBLINK_PREFIX)$(f)$(LD_LIBLINK_SUFFIX))
ADDSLIBS	:= $(foreach f, $(SLIBS), $(S_LIBLINK_PREFIX)$(f))
ADDLIBDIRS 	:= $(foreach f, $(LIBDIRS), $(LD_LIBDIR_FLAG)$(f))
ADDINCDIRS 	:= $(foreach f, $(INCLUDEDIRS), $(C_INCLUDE_FLAG)$(f))

#compiler & flags
CC 		:= g++
CP 		:= cp
MK 		:= mkdir
CFLAGS 		:= -O3 -funroll-all-loops  -fexpensive-optimizations -ffast-math -finline-functions -frerun-loop-opt 
LDFLAGS 	:= -lpthread -ldl -L/usr/X11R6/lib
 
LDFLAGS += $(ADDLIBDIRS) $(ADDLLIBS) $(ADDSLIBS)
CFLAGS += $(ADDINCDIRS) 


#rules
all : $(SOURCES) $(TARGET)

$(TARGET) : md_cl.cpp 
	$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
	$(MK) -p $(BUILDDIR)
	$(CP) -f $(CLFILE) $(BUILDDIR)/$(CLFILE)
	$(CP) -f $(TARGET) $(BUILDDIR)/$(TARGET)


clean :
	rm -rvf $(TARGET)  $(BUILDDIR)/$(CLFILE) $(BUILDDIR)/$(TARGET) $(BUILDDIR)
cls :
	rm -v $(TARGET) $(BUILDDIR)/$(CLFILE) $(BUILDDIR)/$(TARGET)

.PHONY : all clean
